#ifndef classUARTBbufH
 #define classUARTbufH

 #include "CPU_const.h"
 


class UARTbuf
{
//P R I V A T E   V A R I A B L E S
  bool TransON;
  char *pBufIn, *pBufOut;
  uint bufSize, indI, indO, brdI, brdO, brdOISR, trash;
  xQueueHandle qIndI, qBrdI;
  unsigned long xHiPriorTaskWoken;
  unsigned char volatile *pUnTHR;
//////////////////////////////////////////////////////////    

//P U B L I C   V A R I A B L E S
public:
  xSemaphoreHandle mWrBufOen;
//////////////////////////////////////////////////////////    

private://P R I V A T E   F U N C T I O N S  
  void BufFree(void);
  uint CRC16(char *pBuf, uint Xbgn, uint Xend);
//////////////////////////////////////////////////////////    

public://P U B L I C   F U N C T I O N S 
//C L A S S    C O N S T R U C T O R   &   D E S T R U C T O R
  UARTbuf(uint buf_size, unsigned char volatile *pUTHR);
//I N P U T   &   O U T P U T   B U F F E R'S   W R I T E   &   R E A D
  void WrBufIn(char DataIn);
  void WrBufOut(char DataOut);
  char RdBufIn(uint indx);
  bool RdBufOut(void);
//XOR I N P U T   &   O U T P U T   B U F F E R
  bool XORBufOut(uint indx, char DataIn);
  bool XORBufIn(uint indx, char DataIn);
//Q U E U E'S   S E N D   &   R E C E I V E
  void SendIndI(void);
  void RecieveIndI(uint *pIndx);
  bool RecieveIndI(uint *pIndx, portTickType xTicksToWait);
  void SendBrdI(uint Indx);
  void RecieveBrdI(void);
//D I F E R E N T   F U N C T I O N S  
  void ResetBrdI(void);
  void SetBrdOISR(void);
  uint GetBrdO(void);
  uint GetBufSize(void);
  void StartTransmite(void);
  void next(uint *pINDX);
  uint shift(uint Xbgn, uint step);
  uint CountBytes(uint Xbgn, uint Xend);
  bool CheckSize(uint NofBytes);
//I N P U T   &   O U T P U T   C R C 1 6   C A L C U L A T I O N    
  bool CRC16in(uint Xbgn, uint Xend);
  void CRC16out(uint Xbgn);  
//////////////////////////////////////////////////////////    
};

#endif